home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / tcqbsnip.zip / FILEMAN.BAS < prev    next >
BASIC Source File  |  1997-06-25  |  5KB  |  183 lines

  1. 'File Manager Selector
  2. 'FILEMAN.BAS
  3. 'by Tika Carr & Charles Godard, QuickBasic Echo
  4. 'Donated to the Public Domain
  5. 'No Warranties or Guarantees are expressed or implied.
  6.  
  7. 'Features: Fi$ returns the name of the file or directory
  8. '          FiFlag = 1 denotes a file
  9. '          FiFlag = 0 denotes a directory
  10. '          FiFlag = -1 denotes that you were trying to find a file
  11. '                   FL$ will then tell you if the file was found or not
  12. '
  13. ' Some ideas for adding to this program:
  14. '
  15. '    -> Delete File
  16. '    -> Change Directory
  17. '    -> Rename File
  18. '    -> View File
  19. '    -> Edit File
  20. '    -> View/Process if its an Archived file
  21.  
  22. DEFINT A-Z
  23. DECLARE FUNCTION DIR$ (FileSpec$)
  24. DECLARE SUB Selector (Mode$, FileSpec$)
  25.  
  26. '$INCLUDE: 'QB.BI'
  27.  
  28. DIM SHARED InRegs AS RegType, OutRegs AS RegType, DTA AS STRING * 44
  29.  
  30. CONST DOS = &H21
  31. CONST SetDTA = &H1A00
  32. CONST FindFirst = &H4E00, FindNext = &H4F00
  33. CONST Bkgrnd = 1, DirClr = 15, FileClr = 14, HiLite = 4
  34.  
  35. COMMON SHARED Fi$, FiFlag, FL$
  36.  
  37. ' Call the Main Routine. If you wanted to find, say, COMMAND.COM, you'd use:
  38. ' Selector "find", "C:\COMMAND.COM"
  39. ' Note that when getting a directory listing, you MUST use *.*
  40.  
  41. 'To use the selector, use the arrow keys. Spacebar to go to the next page.
  42.  
  43. Selector "", "C:\*.*"
  44.  
  45. LOCATE 25, 1: COLOR 15, Bkgrnd
  46. IF FiFlag = 1 THEN PRINT "File Selected was: "; Fi$;
  47. IF FiFlag = 0 THEN PRINT "Directory Selected was: "; Fi$;
  48. IF FiFlag < 0 THEN PRINT FL$
  49.  
  50. Pause$ = INPUT$(1)
  51.  
  52. FUNCTION DIR$ (FileSpec$) STATIC
  53. Null$ = CHR$(0)
  54.  
  55. InRegs.ax = SetDTA
  56. InRegs.dx = VARPTR(DTA)
  57. INTERRUPT DOS, InRegs, OutRegs
  58.  
  59. IF LEN(FileSpec$) THEN
  60. FileSpecZ$ = FileSpec$ + Null$
  61.  
  62. InRegs.ax = FindFirst
  63. InRegs.cx = &H30
  64. InRegs.dx = SADD(FileSpecZ$)
  65. ELSE
  66. InRegs.ax = FindNext
  67. END IF
  68.  
  69. INTERRUPT DOS, InRegs, OutRegs
  70.  
  71. IF OutRegs.flags AND 1 THEN
  72. DIR$ = ""
  73. ELSE
  74. Null = INSTR(31, DTA, Null$)
  75. DIR$ = MID$(DTA, 31, Null - 30)
  76. END IF
  77.  
  78. END FUNCTION
  79.  
  80. SUB Selector (Mode$, FileSpec$)
  81.  
  82. IF LCASE$(Mode$) = "find" THEN
  83.      IF LEN(DIR$(FileSpec$)) THEN
  84.             FL$ = FileSpec$ + " found."
  85.      ELSE FL$ = FileSpec$ + " not found."
  86.     END IF
  87.     GOTO Done
  88. END IF
  89.  
  90. DIM F$(1 TO 500), d$(1 TO 50)
  91. F = 1: d = 1
  92.  
  93. COLOR , Bkgrnd: CLS
  94. Found$ = DIR$(FileSpec$)
  95.  
  96. ' Get the directories and files into separate arrays.
  97. ' f$ holds the files, d$  holds the directories.
  98.  
  99. DO WHILE LEN(Found$)
  100.      ' The 22nd byte in the DTA string will be CHR$(32) if its a file,
  101.      ' and CHR$(16) if its a directory.
  102.      IF ASC(MID$(DTA, 22, 1)) = 32 THEN F$(F) = Found$: F = F + 1
  103.      IF ASC(MID$(DTA, 22, 1)) = 16 THEN d$(d) = Found$: d = d + 1
  104.      Found$ = DIR$("")
  105. LOOP
  106.  
  107. ' Alphabetize the arrays
  108. F = F - 1: FOR a = 1 TO F: FOR b = 1 TO F - 1
  109.      IF F$(b) > F$(b + 1) THEN SWAP F$(b), F$(b + 1)
  110. NEXT b, a
  111.  
  112. d = d - 1: FOR a = 1 TO d: FOR b = 1 TO d - 1
  113.      IF d$(b) > d$(b + 1) THEN SWAP d$(b), d$(b + 1)
  114. NEXT b, a
  115.  
  116. 'Print the color coded Directories and Files
  117. COLOR DirClr: FOR a = 1 TO d: PRINT d$(a), : NEXT
  118. COLOR FileClr:
  119. FOR a = 1 TO F:
  120.  IF UBOUND(d$) + a = 121 THEN PCOPY 0, 1: CLS
  121.  PRINT F$(a), : NEXT: PCOPY 0, 2
  122.  
  123. 'Start up by hilighting the first File or Directory.
  124. 'cl stores the foreground color of the file currently being pointed to.
  125. y = 1
  126. Fi$ = "": FOR x = 1 TO 12
  127. Fi$ = Fi$ + CHR$(SCREEN(y, x, 0))
  128. cl = VAL("&H" + RIGHT$(HEX$(SCREEN(y, x, 1)), 1))
  129. NEXT x
  130. x = x - 12
  131. LOCATE y, x: COLOR cl, HiLite
  132. PRINT Fi$;
  133.  
  134. 'Here's the "Main guts" - it lets you select the files.
  135. P$ = "": Page1 = 1: Page2 = 2
  136. PCOPY Page2, 0: SWAP Page1, Page2   'make sure first page is displayed.
  137. Sel:
  138. P$ = INKEY$: IF P$ = "" THEN GOTO Sel
  139. IF P$ = " " THEN        'use space bar to switch pages
  140.      IF page = 1 THEN page = 2 ELSE page = 1
  141.      PCOPY page, 0: SWAP Page1, Page2: Fi$ = ""
  142. END IF
  143. IF P$ = CHR$(13) THEN COLOR 7, 0: GOTO Done
  144. IF LEN(P$) = 2 THEN
  145.      COLOR cl, Bkgrnd: LOCATE y, x: PRINT Fi$
  146.      P1$ = RIGHT$(P$, 1)
  147.      IF P1$ = "H" THEN y = y - 1: IF y < 1 THEN y = 1    'up
  148.      IF P1$ = "K" THEN x = x - 14: IF x < 1 THEN x = 1    'left
  149.  
  150.      'down
  151.      IF P1$ = "P" THEN
  152.             'test to see if there's another file/dir
  153.             IF SCREEN(y + 1, x, 0) <> 32 THEN y = y + 1
  154.             IF y > 23 THEN y = 23
  155.      END IF
  156.  
  157.      'right
  158.      IF P1$ = "M" THEN
  159.             'test to see if there's another file/dir
  160.             IF SCREEN(y, x + 14, 0) <> 32 THEN x = x + 14
  161.             IF x > 57 THEN x = 57
  162.      END IF
  163.      Fi$ = ""
  164.      cl = VAL("&H" + RIGHT$(HEX$(SCREEN(y, x, 1)), 1))
  165.      FOR x1 = x TO x + 12
  166.             Fi$ = Fi$ + CHR$(SCREEN(y, x1, 0))
  167.      NEXT x1
  168.      LOCATE y, x: COLOR cl, HiLite: PRINT Fi$;
  169. END IF
  170. GOTO Sel
  171.  
  172. Done:
  173. ' Set flags for return to main program. See comments at start of the main
  174. ' program.
  175. IF LCASE$(Mode$) <> "find" THEN
  176.      IF cl = FileClr THEN FiFlag = 1 ELSE FiFlag = 0
  177. ELSE
  178.      FiFlag = -1
  179. END IF
  180.  
  181. END SUB
  182.  
  183.